<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PaymentController
 *
 * @author Sorasak Siangsanan
 */
class PaymentController extends Controller {

    public function actionIndex() {
        $model = new PaymentForm();

        // collect user input data
        if (isset($_POST['PaymentForm'])) {
            $model->payment_date = $_POST['PaymentForm']['payment_date'];
            $model->attributes = $_POST['PaymentForm'];
            $model->order = $_POST['PaymentForm']['order'];
            $model->remark = $_POST['PaymentForm']['remark'];

            // validate user input and redirect to the previous page if valid
            if ($model->validate() && $model->payment()) {
                $message = Yii::t('wait', 'foretellSaved');
                $redirectPage = Yii::app()->getBaseUrl(true) . '/index.php?r=payment';
                $this->redirect(array('/wait', 'message' => $message, 'redirectPage' => $redirectPage));
                return;
//                $this->redirect(Yii::app()->user->returnUrl);
            }
        }

        $this->render('index', array('model' => $model));
    }
    
    public function actionVieworder() {

        $id = $_GET["id"];
        if (isset($id)) {
            $order = Order::model()->findByPk($id);
            if (!isset($order)) {
                $this->redirect(array('payment/index'));
            }
        } else {
            $this->redirect(array('payment/index'));
        }

        $this->render('vieworder', array('order' => $order));
    }

}
